package experiment2.springbootautoconfigdemo.config;

import experiment2.springbootautoconfigdemo.common.CustomCommandLineRunner;
import experiment2.springbootautoconfigdemo.common.CustomProperties;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 创建一个自定义的自动配置类。
 * 并给自动配置类添加有效条件
 */
//并指定装配的属性Bean
@EnableConfigurationProperties(CustomProperties.class)
public class hxieAutoConfig {
    @Bean
    //利用 @ConditionalOnProperty 注解，添加(有效)属性条件-判断自动装配的配置类是否生效
    @ConditionalOnProperty(prefix = "hxie.auto",name = "enable",havingValue = "true")
    CommandLineRunner createCustomCommandLineRunner(Environment env){
        return new CustomCommandLineRunner(env);
    }
}
